import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Cart from '../components/Cart.vue'
import Search from '../components/Search.vue'
import Details from '../components/Details.vue'
import Order from '../components/Order.vue'
import Address from '../components/Address.vue'
import AddressEdit from '../components/AddressEdit.vue'

import Categories from '../components/categories/Categories'
import GoodsList from '../components/categories/GoodsList'
import Myinfo from '../components/Myinfo'
Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/cart',
    component: Cart
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/details/:id',
    name: 'Details',
    component: Details
  },

  {
    path: '/categories',
    component: Categories
  },
  {
    path: '/goodsList/:cateName',
    name: 'goodsList',
    component: GoodsList
  },
  {
    path: '/goodsList/:id/:cateName',
    name: 'cateList',
    component: GoodsList
  },
  {
    path: '/order',
    component: Order
  },
  {
    path: '/details/:id',
    name: 'details',
    component: Details
  },
  {
    path: '/address',
    component: Address,
  },
  {
    path: '/address/edit',
    component: AddressEdit
  },
  {
    path: '/myinfo',
    component: Myinfo
  },
]

const router = new VueRouter({
  routes
})
// 路由拦截
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') return next()
//   const token = sessionStorage.getItem('token')
//   if (!token) return next('/login')
//   next()
// })

export default router